package com.zgw.his.emr.workbench;

import java.util.ArrayList;
import java.util.List;

import com.zgw.his.emr.model.PageRecord;
import com.zgw.his.emr.model.RootRecord;
import com.zgw.his.emr.widget.MedicalPage;

/**
 * 页面容器 用于构建和存放Page
 * */
public abstract class MedicalContainer {
	protected List<MedicalPage> pages;
	protected MedicalPage currentPage;
	protected RootRecord record;
	protected String content;

	// 初始化容器环境
	public void initialization(String content) {
		try {
			this.content = content;
			initialization(parser());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void initialization(RootRecord record) {
		clear(); // 清空环境
		this.record = record;
		createPages();
	}

	protected void createPages() {
		for (PageRecord r : record.getPageRecords()) {
			pages = new ArrayList<MedicalPage>();
			MedicalPage page = createPage();
			page.initialize(r);
			pages.add(page);
		}
	}

	public void refresh_record() {
		if (pages != null) {
			for (MedicalPage p : pages) {
				p.refresh_record();
			}
		}
	}

	public void clear() {
		if (pages != null) {
			for (MedicalPage p : pages) {
				p.dispose();
			}
		}
	}

	public List<MedicalPage> getPages() {
		return pages;
	}

	public MedicalPage getCurrentPage() {
		return currentPage;
	}

	public RootRecord getRecord() {
		return record;
	}

	// 解析记录-
	public abstract RootRecord parser() throws Exception;

	// 创建页
	public MedicalPage createPage() {
		return new MedicalPage();
	}

	// 显示页
	public abstract void showPage(MedicalPage page);

}
